<template>
    <div>
         <ul class="nav nav-tabs" role="tablist">
            <li role="presentation" class="active"><a href="#qgwrk" role="tab" data-toggle="tab">请购未入库</a></li>
            <li role="preaentation"><a href="#instock" role="tab" data-toggle="tab">入库记录</a></li>
        </ul>
        <div class="tab-content">
            <div role="tabpanel" class="tab-pane active" id="qgwrk">
                <table id="instock_table" class="table"></table>
                <div class="modal fade" id="instock_add_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title" id="exampleModalLabel">入库确认</h4>
                            </div>
                            <div class="modal-body">
                                <p>确认入库?</p>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                <button type="button" class="btn btn-primary" @click="instock">确认</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div role="tabpanel" class="tab-pane" id="instock">
                <table id="instockrecord_table"></table>
            </div>
        </div>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                currentRow: ''
            }
        },
        methods: {
            getNotInstock() {
                var _this = this
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/purchasedetail/getpurchasenotinstock',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                    },
                    dataType: 'json',
                    // async: false,
                    crossDomain: true,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误')
                    },
                    success: function(retdata) {
                        var operateEvents = {
                            'click a[name="instock"]': function(e, value, row, index) {
                                _this.currentRow = row
                                _this.showInstockModal()
                            }
                        }
                        $('#instock_table').bootstrapTable('destroy')
                        $('#instock_table').bootstrapTable({
                            data: retdata.Table2,
                            columns: [{
                                field: 'fidno',
                                title: '请购详单号',
                                halign: 'center'
                            }, {
                                field: 'fitemidno',
                                title: '物料编号',
                                halign: 'center'

                            }, {
                                field: 'fcgn',
                                title: '物料名称',
                                halign: 'center'

                            }, {
                                field: 'fmodel',
                                title: '型号',
                                halign: 'center'

                            }, {
                                field: 'type',
                                title: '类型',
                                halign: 'center'

                            }, {
                                field: 'unit',
                                title: '单位',
                                halign: 'center'

                            }, {
                                field: 'fqty',
                                title: '数量',
                                halign: 'center'

                            }, {
                                field: 'fprice',
                                title: '单价',
                                halign: 'center'

                            }, {
                                field: 'fnotes',
                                title: '备注',
                                halign: 'center'

                            }, {
                                field: 'operare',
                                title: '操作',
                                halign: 'center',
                                formatter: '<a class="btn btn-success btn-xs" name="instock">入库</a>',
                                events: operateEvents
                            }],
                            pagination: true,
                            paginationLoop: true,
                            onlyInfoPagination: false,
                            striped: true,
                            //sortOrder: 'desc',
                            sidePagination: 'client',
                            pageNumber: 1,
                            pageSize: 10,
                            pageList: [10, 25, 50, 100],
                            smartDisplay: true,
                            selectItemName: 'material',
                            search: true,
                            searchOnEnterKey: false,
                            strictSearch: false,
                            showHeader: true,
                            maintainSelected: true,
                            //showFooter: true,
                            showColumns: true,
                            showRefresh: true,
                            // showToggle: true,
                            showPaginationSwitch: true,
                            //detailView: true,
                            // clickToSelect: true,
                            singleSelect: false,
                            checkboxHeader: false,
                            // radio: true,
                            checkbox: true,
                        });
                    }
                });
            },
            getInstock() {
                var _this = this
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/instock/fetchallinstock',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                    },
                    dataType: 'json',
                    // async: false,
                    crossDomain: true,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误');
                    },
                    success: function(retdata) {
                        $('#instockrecord_table').bootstrapTable('destroy')
                        $('#instockrecord_table').bootstrapTable({
                            data: retdata.Table2,
                            columns: [{
                                field: 'fidno',
                                title: '入库单号',
                                halign: 'center'
                            }, {
                                field: 'fdid',
                                title: '请购单号',
                                halign: 'center'

                            }, {
                                field: 'fitemno',
                                title: '物料号',
                                halign: 'center'

                            }, {
                                field: 'fcgn',
                                title: '物料名称',
                                halign: 'center'

                            }, {
                                field: 'fmodel',
                                title: '型号',
                                halign: 'center'

                            }, {
                                field: 'fprice',
                                title: '单价',
                                halign: 'center'

                            }, {
                                field: 'fqty',
                                title: '数量',
                                halign: 'center'

                            }, {
                                field: 'entuser',
                                title: '入库人',
                                halign: 'center'

                            }, {
                                field: 'entdate',
                                title: '入库日期',
                                halign: 'center'

                            }],
                            pagination: true,
                            paginationLoop: true,
                            onlyInfoPagination: false,
                            striped: true,
                            //sortOrder: 'desc',
                            sidePagination: 'client',
                            pageNumber: 1,
                            pageSize: 10,
                            pageList: [10, 25, 50, 100],
                            smartDisplay: true,
                            selectItemName: 'material',
                            search: true,
                            searchOnEnterKey: false,
                            strictSearch: false,
                            showHeader: true,
                            maintainSelected: true,
                            //showFooter: true,
                            showColumns: true,
                            showRefresh: true,
                            // showToggle: true,
                            showPaginationSwitch: true,
                            //detailView: true,
                            // clickToSelect: true,
                            singleSelect: false,
                            checkboxHeader: false,
                            // radio: true,
                            checkbox: true,
                        });
                    }
                });
            },
            showInstockModal() {
                $('#instock_add_modal').modal('show');
            },
            instock() {
                var _this = this
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/instock/add',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                        'fdid': _this.currentRow.fidno,
                        'fitemno': _this.currentRow.fitemidno,
                        'fcgn': _this.currentRow.fcgn,
                        'fmodel': _this.currentRow.fmodel,
                        'fprice': _this.currentRow.fprice,
                        'fqty': _this.currentRow.fqty,
                        'ftype': true
                    },
                    dataType: 'json',
                    async: false,
                    crossDomain: true,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误')
                    },
                    success: function(retdata) {
                        $('#instock_add_modal').modal('hide');
                        _this.getNotInstock()
                        _this.getInstock()
                    }
                });
            }
        },
        mounted() {
            this.getNotInstock()
            this.getInstock()
        }
    }
</script>
<style>

</style>